package lormi.meipin.service.impl;


import java.util.List;

import org.springframework.stereotype.Service;

import lormi.meipin.common.LMRongYunAPI;
import lormi.meipin.dto.CurrencyDto;
import lormi.meipin.entity.FocusPosition;
import lormi.meipin.entity.Position;
import lormi.meipin.exception.LMException;
import lormi.meipin.service.BaseService;
import lormi.meipin.service.IFocusPositionService;
import lormi.meipin.vo.PositionSearchVo;

@Service
public class FocusPositionService extends BaseService implements IFocusPositionService{

	
	@Override
	public void focusPosition(Integer memId, Integer positionId) throws LMException {
		if (focusPositionMapper.selectByMemIdAndPositionId(memId, positionId, 1)!=null) {
			throw new LMException(100022);
		}
		Position position = positionMapper.selectByPrimaryKey(positionId);
		if (focusPositionMapper.insert(new FocusPosition(positionId,position.getMerid(),memId,1))<1) {
			throw new LMException(100035);
		}
		//推送通知
		LMRongYunAPI.push(position.getMerid()+"",talentMapper.selectByMemId(memId).getName(), 12);
	}
	@Override
	public void cancelFocusPosition(Integer memId, Integer positionId) throws LMException {
		FocusPosition focusPosition = focusPositionMapper.selectByMemIdAndPositionId(memId, positionId, 1);
		if (focusPosition==null) {
			throw new LMException(170005);
		}
		if (focusPositionMapper.deleteByPrimaryKey(focusPosition.getId())<1) {
			throw new LMException(130010);
		}
	}
	@Override
	public List<PositionSearchVo> getFocusList(CurrencyDto dto) throws LMException {
		List<PositionSearchVo> list = positionMapper.selectFocusList(dto.getUserid(), dto.getOffset(), dto.getPagesize());
		if (list==null || list.size()<1) {
			throw new LMException(100028);
		}
		return list;
	}
	
	
}
